package com.edu.user.controller;


import com.edu.entity.SysUserInfo;
import com.edu.user.service.ISysUserInfoService;
import com.edu.vo.PageResultVO;
import com.edu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author jr
 * @since 2021-04-13
 */
@CrossOrigin
@RestController
@RequestMapping("manage")
public class SysUserInfoController {

    @Autowired
    private ISysUserInfoService userInfoService ;

    /**
     * 用户登录
     * @param userInfo
     * @return
     * @throws Exception
     */
    @RequestMapping("login")
    public Result login(@RequestBody SysUserInfo userInfo) throws Exception {


        Result result = userInfoService.login(userInfo);

        return result;
    }

    @RequestMapping("verify")
    public Result verify( String token){
        Result result = userInfoService.verifyToken(token);
        return result;
    }
    /**
     * 查询用户列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("user/queryListByPage")
    public PageResultVO<SysUserInfo> queryUserListByPage(@PathParam("currentPage") Integer currentPage ,
                                                        @PathParam("pageSize") Integer pageSize,
                                                         @PathParam("name") String name ){


        return userInfoService.queryListByPage(currentPage,pageSize,name);
    }

    /**
     * 添加
     * @return
     */
    @ResponseBody
    @RequestMapping("user/userAdd")
    public Result userAdd( SysUserInfo userInfo) {

        return userInfoService.userAdd(userInfo);
    }



    @ResponseBody
    @RequestMapping("user/deleteById")
    public Result deleteById( Integer id) {

        System.out.println(id);
        userInfoService.deleteById(id);

        return null;
    }

    @ResponseBody
    @RequestMapping("user/deleteByIds")
    public Result deleteByIds(@RequestParam("ids[]") List<Integer> ids) {

        System.out.println(ids);
        for (int id: ids) {
            userInfoService.deleteById(id);
        }

        return null;
    }

    @ResponseBody
    @RequestMapping("user/updateById")
    public Result updateUserById(SysUserInfo userInfo) {

        System.out.println(userInfo);


        return userInfoService.updateUserById(userInfo);
    }

}
